<!--
笔记修改
 add by yyp 2019-05-25
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Note" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" )
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item.short(label="用户名" prop="userName" v-bind:label-width="labelWidth" v-bind:rules="rules.userName")
        el-select(v-model="formModel.userId" placeholder="请选择" @change="getUid")
          el-option(v-for="item in options" v-bind:key="item.id" v-bind:label="item.name" v-bind:value="item.id")
      el-form-item(label="笔记标题" prop="noteTitle" label-width="120px" v-bind:rules="rules.noteTitle")
        el-input(v-model="formModel.noteTitle" style="width:80%")
      el-form-item.short(label="笔记附件" prop="noteEnclosure" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="img"  :fileList="fileList" tipText="只能上传jpg/png文件")
      kalix-img-upload.img-margin(v-model="formModel.noteEnclosure" readonly="readonly" v-on:ImgDel="ImgDel")
      el-form-item(label="笔记详情" prop="noteContent" label-width="120px" v-bind:rules="rules.noteContent")
        el-input(v-model="formModel.noteContent" style="width:80%"  type="textarea")


</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {NoteURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  import KalixImgUpload from '../../../../../components/corelib/components/common/imgUpload'
  export default {
    name: 'noteEdit',
    components: {
      KalixSelect,
      KalixClansmanUpload,
      KalixImgUpload
    },
    data() {
      return {
        action: baseURL + '/camel/rest/upload',
        formModel: Object.assign({}, FormModel),
        rules: {
          name: [{required: true, message: '请输入修改的名称', trigger: 'blur'}]
        },
        targetURL: NoteURL,
        labelWidth: '110px',
        filePathArr: [],
        fileList: [],
        options: []
      }
    },
    mounted() {
      this.getUname()
    },
    methods: {
      getFilePath(filePath, fileName) {
        this.formModel.noteEnclosure = filePath
      },
      ImgDel(noteEnclosure) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          let arrImg = this.formModel.noteEnclosure.split(',')
          console.log('arrImg++++++++++++++', arrImg)
          let idx = arrImg.indexOf(noteEnclosure)
          arrImg.splice(idx, 1)
          this.formModel.noteEnclosure = arrImg.join(',')
          console.log('this.formModel.imgUrl++++++++++++++', this.formModel.noteEnclosure)
          // this.filePathArr = arrImg
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      init(dialogOption) {
        console.log('---------dialogOption------------', dialogOption)
      },
      getUname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          console.log('res========', res.data)
          this.options = res.data.data
        })
      },
      getUid(val) {
        let obj = {}
        obj = this.options.find((item) => {
          return item.id === val
        })
        this.formModel.userName = obj.name
        console.log('bbbbbbbbbbbbbbbbbbbbbb', this.formModel.userName)
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 50%
    margin auto
    .radio
      margin-left 150px
      margin-bottom 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
  .img-margin
    margin-left 150px
</style>
